<template>
    <div class="xlSeeFrom">
      <div class="tab-item">
        <!--工资单说明-->
        <div class="item">
          <p class="tab-title">Payroll Description</p>
          <div class="tab">
            <table>
              <tr>
                <td>Payroll ID</td>
                <td>Prepared by</td>
                <td>Belong Time</td>
                <td>Submit Time</td>
              </tr>
              <tr>
                <td>{{form.salary_id}}</td>
                <td>{{form.hr_name}}</td>
                <td>{{form.belong_date}}</td>
                <td>{{form.submit_time}}</td>
              </tr>
            </table>
          </div>
        </div>
        <!--汇率-->
        <div class="item">
          <p class="tab-title">Set Exchange Rate</p>
          <div class="tab">
            <table>
              <tr>
                <td>EUR-UAH</td>
                <td>USD-UAH</td>
                <td>CNY-UAH</td>
              </tr>
              <tr>
                <td>{{form.eur_to_uah}}</td>
                <td>{{form.usd_to_uah}}</td>
                <td>{{form.cny_to_uah}}</td>
              </tr>
            </table>
          </div>
        </div>
      </div>
      <!--项目统计-->
      <div class="project" style="width: 100%;height: 400px;">
        <div class="title">Amount</div>
        <div class="contetn">
          <div  style="width:100%;border-bottom: 1px solid #eee;">
            <div class="top">
              <div class="item">
                <div>project</div>
                <div>{{this.projectNum}}</div>
              </div>
              <div class="item">
                <div>amount（UAH）</div>
                <div>{{this.totalAmount.toFixed(2)}}</div>
              </div>
            </div>
          </div>
          <div ref="myChart" style="height:300px;width:100%">
          </div>
        </div>
      </div>
      <!--员工列表-->
      <div class="personList">
        <div class="title">
          Staff Information
        </div>
        <template>
          <el-table
            :header-cell-style="{background:'#F2F6FC',color:'#606266'}"
            :data="tableData"
            border
            style="width: 99.9%"
            ref="tableData"
            class="emp_table"
            v-if="tableData">
            <el-table-column
              align="center"
              prop="pe_number"
              label="PE Number"
              width="180">
            </el-table-column>
            <el-table-column
              align="center"
              prop="pe_name"
              label="PE Name">
            </el-table-column>
            <el-table-column
              align="center"
              prop="salary_money"
              label="Salary">
            </el-table-column>
            <el-table-column
              align="center"
              prop="contract_currency"
              label="Contract Currency">
            </el-table-column>
            <el-table-column
              align="center"
              prop="payment_currency"
              label="Payment Currency">
            </el-table-column>
            <el-table-column
              align="center"
              prop="pay_money"
              label="Pay Money(payment currency)">
            </el-table-column>
            <el-table-column
              align="center"
              label="Action">
              <template slot-scope="scope">
                <el-button type="text" size="small" @click="seeWorkHour(scope.row.pe_username)">see working hours</el-button>
              </template>
            </el-table-column>
          </el-table>
        </template>
        <el-pagination
          align="right"
          @current-change="curChange"
          :current-page.sync="curPage"
          :page-size="10"
          layout="total,prev,pager,next,jumper"
          :total="count">
        </el-pagination>
      </div>

      <seeWorkHour ref="seeWorkHour"></seeWorkHour>
      <div style="float: right;margin: 10px;">
        <el-button type="success" @click="close">Close</el-button>
      </div>
    </div>


</template>

<script>
import {getSalaryDetail} from '@/request/other_api'
import seeWorkHour from "./seeWorkHour";

import echarts from 'echarts'

export default {
  data(){
    return {
      form:{},
      tableData: [],
      curPage:1,
      count:0,
      projectNum:0,
      totalAmount:0,
      projects:[]
    }
  },
  components:{
    seeWorkHour
  },
  mounted () {
    this.formatData(this.$route.params.id)
  },
  methods:{
    close(){
      window.opener = null;
      window.close();
    },
    formatData(salaryID){
      getSalaryDetail({
        salary_id:salaryID
      }).then(res => {
        this.form = res.salary_base
        this.tableData = res.data
        this.count = res.count
        this.projectNum = res.project_number
        this.totalAmount = res.total_money
        this.projects = res.projects_money
      }).then(res => {
        this.$nextTick(() => {
          this.initData()
        })
      })
    },
    //初始化数据
    initData() {
      let myChart = echarts.init(this.$refs.myChart);
      let projectsData = []
      this.projects.forEach(item => {
        projectsData.push({'value':item.project_money,'name':item.project_name})
      })
      let projectsName = []
      this.projects.forEach(item => {
        projectsName.push(item.project_name)
      })
      let option = {
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b}: {c} ({d}%)'
        },
        legend: {
          orient: 'vertical',
          right: 200,
          data: projectsName
        },
        series: [
          {
            type: 'pie',
            radius: ['50%', '70%'],
            center: ['50%', '50%'],
            avoidLabelOverlap: false,
            label: {
              show: false,
              position: 'center'
            },
            // emphasis: {
            //   label: {
            //     show: true,
            //     fontSize: '15',
            //     fontWeight: 'bold'
            //   }
            // },
            labelLine: {
              show: false
            },
            data: projectsData,
            itemStyle: {
              emphasis: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ],
      };
      myChart.setOption(option);
    },
    //查看项目工时
    seeWorkHour(pe_username){
      this.$refs.seeWorkHour.editDialog = true
      this.$refs.seeWorkHour.formatData(this.form,pe_username)
    },
    //  点击每页刷新获取数据
    curChange (currentPage) {
      this.curPage = currentPage
      this.getEmp()
    },
    // 上一页
    prevClick () {
      this.curPage < 1 ? this.curPage = 1 : this.curPage--
      this.getEmp()
    },
    // 下一页
    nextClick () {
      this.curPage >= this.count ? this.curPage = this.count : this.curPage++
      this.getEmp()
    },
    getEmp(){
      getSalaryDetail({
        salary_id:this.$route.params.id,
        page:this.curPage
      }).then(res =>{
        if (res.code == 200) {
          this.tableData = res.data
          this.count = res.count
        }
      })
    }
  },
}
</script>

<style lang="less" scoped>
/deep/ .el-form-item__label {
  background-color: #eee;
  text-align: center;
  //width: 121px;
}
/deep/ .el-dialog__header {
  padding: 20px 20px 10px;
  border-bottom: 1px solid #eee;
}
/deep/ .el-dialog__body {
  padding: 10px 20px;
  color: #333;
  font-size: 15px;
  word-break: break-all;
}
.step{
  margin-bottom: 10px;
}
.content{
  margin-top: 10px;
  margin-bottom: 10px;

}
.tab-item{
  width: 99.9%;
  padding: 10px 0;
  border: 1px solid #eee;

  table{
    width: 100%;
    font-family: verdana,arial,sans-serif;
    font-size:14px;
    color:#333333;
    border-width: 1px;
    border-color: #999999;
    border-collapse: collapse;
  }
  table td{
    border-width: 1px;
    padding: 4px;
    border-style: solid;
    border-color: #999999;
    width: 25%;
  }
  table tr:nth-child(2n+1){
    background-color:#F2F6FC;
    height:50px;
    text-align: center;
  }
  table tr:nth-child(2n){
    background-color: #fff;
    height:50px;
    text-align: center;
  }

.tab-title{
  font-family: SourceHanSansSC;
  font-weight: 700;
  font-size: 20px;
  color: rgb(16, 16, 16);
  font-style: normal;
  letter-spacing: 0px;
  line-height: 30px;
  text-decoration: none;
  padding: 5px 10px;
}
/deep/ .el-date-editor.el-input, .el-date-editor.el-input__inner {
  width: 100%;
 }
}

.project{
  .title{
    font-family: SourceHanSansSC;
    font-weight: 700;
    font-size: 20px;
    color: rgb(16, 16, 16);
    font-style: normal;
    letter-spacing: 0px;
    line-height: 30px;
    text-decoration: none;
    padding: 5px 10px;
    border-bottom: 1px solid #eee;
  }

  .contetn{

    .top{
      display: flex;
      justify-content: space-around;
      margin-top: 25px;
      text-align: center;
      .item div:first-child{
        font-family: SourceHanSansSC;
        font-weight: 400;
        font-size: 14px;
        color: rgb(169, 169, 169);
        font-style: normal;
        letter-spacing: 0px;
        line-height: 21px;
        text-decoration: none;
      }
      .item div:last-child{
        font-family: SourceHanSansSC;
        font-weight: 700;
        font-size: 36px;
        color: rgb(44, 48, 57);
        font-style: normal;
        letter-spacing: 0px;
        line-height: 53px;
        text-decoration: none;
      }
    }
    .bot{
      .item{
        display: flex;
        .left{
          width: 10px;
          height: 10px;
          background-color: #0000FF;
        }
      }
    }
  }
}

.personList{
  .title{
    font-family: SourceHanSansSC;
    font-weight: 700;
    font-size: 20px;
    color: rgb(16, 16, 16);
    font-style: normal;
    letter-spacing: 0px;
    line-height: 30px;
    text-decoration: none;
    padding: 5px 10px;
    border-bottom: 1px solid #eee;
  }
}

</style>
